<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="entity.Owner" %>
<%@ page import="entity.AccountBalance" %>
<%@ page import="dao.AccountBalanceDao" %>
<%@ page import="java.util.List" %>
<html>
<head>
    <title>账户余额</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
            padding-top: 2rem;
        }
        .card {
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border: none;
        }
        .back-link {
            text-decoration: none;
            color: #6c757d;
        }
        .back-link:hover {
            color: #5a6268;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <%
                // 检查用户是否登录
                Owner owner = (Owner) session.getAttribute("owner");
                if (owner == null) {
                    response.sendRedirect("login.jsp");
                    return;
                }

                // 获取账户余额信息
                AccountBalanceDao balanceDao = new AccountBalanceDao();
                List<AccountBalance> balances = balanceDao.getBalancesByOwnerId(owner.getId());
            %>

            <a href="index.jsp" class="back-link mb-3 d-inline-block">
                <i class="bi bi-arrow-left"></i> 返回首页
            </a>

            <div class="card">
                <div class="card-body">
                    <h2 class="card-title text-center mb-4">账户余额查询</h2>
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead class="table-light">
                            <tr>
                                <th>费用类型</th>
                                <th>当前余额</th>
                                <th>计费单位</th>
                            </tr>
                            </thead>
                            <tbody>
                            <% for (AccountBalance balance : balances) { %>
                            <tr>
                                <td><%= balance.getFeeTypeName() %></td>
                                <td><%= balance.getBalance() %></td>
                                <td><%= balance.getUnit() %></td>
                            </tr>
                            <% } %>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>